package com.shuiyun.controller;

import com.shuiyun.entity.Menu;
import com.shuiyun.entity.SysMenu;
import com.shuiyun.service.SysMenuService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by liliting on 18/3/16
 * 菜单部分
 */
@Controller
@RequestMapping("sys")
public class SysMenuController {

    @Resource
    private SysMenuService sysMenuService;

    @RequestMapping("menu/user")
    @ResponseBody
    public Menu getMenu() {
        List<SysMenu> list = sysMenuService.findMenu();
        Menu menu = new Menu();
        for (SysMenu sysMenu : list) {
            if (sysMenu.getType() == 0) {
                menu.getMenuList().add(sysMenu);
            }
        }
        for (SysMenu sysMenu : list) {
            if (sysMenu.getType() == 1) {
                for (SysMenu sysMenu1 : menu.getMenuList()) {
                    if (sysMenu1.getMenuId().longValue() == sysMenu.getParentId().longValue())
                        sysMenu1.getList().add(sysMenu);
                }
            } else if (sysMenu.getType() == 2) {
                for (SysMenu sysMenu2 : menu.getMenuList()) {
                    menu.getPermissions().add(sysMenu2.getPerms());
                }
            }
        }
        menu.setCode(0);
        return menu;
    }
}